﻿using NewAI.Game;
using NewAI.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace NewAI.FSM.JsonAnalyzerFSM
{
    public class JsonAnalyseState : State<JsonAnalyzer>
    {
        private string json;
        public JsonAnalyseState(String json)
        {
            this.json = json;
        }

        public override void Enter(JsonAnalyzer entity)
        {
            entity.StartTimeOurTimer();
            MessageType mt = ServerMessageTypePaser.Parse(json);
            switch (mt)
            {
                case MessageType.Leg_start:

#if DEBUG
                    EasyTimestamp.Init();
#endif

                    var legStartDate = ParseLegStartData.GetMapData(json);
                    GV.MapWidth = legStartDate.MapWidth;
                    GV.MapHeight = legStartDate.MapHeight;
                    entity.LegStartMessage.Call(null, new FSMEventEventArg(legStartDate));
                    break;
                case MessageType.Round:
                    RoundData roundData = (new ParseRoundData(json)).GetRoundDataObj();
                    entity.roundID = roundData.RoundID;
                    entity.OneRoundMessage.Call(null, new FSMEventEventArg(roundData));
                    break;
                case MessageType.Leg_end:
                    entity.LegEndMessage.Call(null, new FSMEventEventArg((new ParseLegEndData(json)).GetLegEndDataObj()));
                    break;
                case MessageType.Game_over:
                    PubliceMessage.CloseAllMessage.Call(null, new FSMEventEventArg("Game Over！"));
                    break;
                case MessageType.Nothing:
                    break;
                default:
                    break;
            }
        }
    }
}
